<template>
  <div>
    <div id="OAOnline-img"></div>
    <h1>行业解决方案丰富</h1>
    <p>85个行业，20000多家客户的选择，丰富的行业解决方案</p>

    <div style=" width:1200px; padding-top: 50px; margin: 0 auto; position: relative;">
      <el-image src="https://22159555.s21i.faiusr.com/4/ABUIABAEGAAgpICU8wUohYmisAYw0Qk45gc!700x700.png.webp"></el-image>
      <el-image
          style="position: absolute; top: 55%; left: 53%;  transform: translate(-50%, -50%);  /* 将 <p> 标签定位到中心位置 */"
          src="https://22159555.s21i.faiusr.com/4/ABUIABAEGAAgo4CU8wUo7fCwuQIwmgc41QU!450x450.png.webp">
      </el-image>
    </div>

    <div id="medication-div-footer">
      <el-button style="font-size: 18px;width: 180px; height: 55px; margin-top: 80px"
                 @click="dialogFormVisible = true">马上体验
      </el-button>
    </div>

    <el-dialog title="请填写您的信息" :visible.sync="dialogFormVisible">
      <span style="color: #666666; font-size: 12px;">亲爱的朋友，为更好的为您服务，请您填写以下信息或致电400-86-18580，我们的工作人员会尽快与您联系！</span>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="手机" prop="customerPhone">
          <el-input v-model="ruleForm.customerPhone"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="customerName">
          <el-input v-model="ruleForm.customerName"></el-input>
        </el-form-item>
        <el-form-item label="行业" prop="customerIndustry">
          <el-input v-model="ruleForm.customerIndustry"></el-input>
        </el-form-item>
        <el-form-item style="text-align: right">
          <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
          <el-button type="warning" @click="dialogFormVisible = false">返回</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: "OAOnlineView",
  data() {
    return {
      /*新增客户*/
      dialogFormVisible: false,
      ruleForm: {
        customerPhone: '',
        customerName: '',
        customerIndustry: '',
      },
      rules: {
        customerPhone: [
          {required: true, message: '请输入您的手机号', trigger: 'blur'},
          {pattern: /^1[34578]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur'}
        ],
        customerName: [
          {required: true, message: '请输入您的姓名', trigger: 'blur'},
          {min: 2, max: 25, message: '长度在 2 到 25 个字符', trigger: 'blur'}
        ],
        customerIndustry: [
          {required: true, message: '请输入您所在行业', trigger: 'blur'},
          {min: 2, max: 25, message: '长度在 2 到 25 个字符', trigger: 'blur'}
        ]
      },
      formLabelWidth: '100px'


    }
  },

  methods:{
    /*添加*/
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = 'http://localhost:8080/customer/insert';
          let jsonData = {
            customerPhone: this.ruleForm.customerPhone,
            customerName: this.ruleForm.customerName,
            customerIndustry: this.ruleForm.customerIndustry
          };
          this.axios({
            method: 'post',
            url: url,
            headers: { 'Content-Type': 'application/json' },
            data: JSON.stringify(jsonData)       //将参数转为json格式
          }).then((response) =>{
            let jsonResult = response.data;
            if (jsonResult.code == 200){
              this.$message({
                message:'提交成功!',
                type:'sucess'
              });
              this.resetForm(formName);
              this.dialogFormVisible = false;
            }else {
              this.$alert(jsonResult.message, '错误', {
                confirmButtonText: '确定',
                callback: action => {
                }
              });
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },

    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
}
</script>

<style scoped>
#medication-div-footer {
  margin-top: 50px;
  height: 200px;
  background-image: url('../../../assets/footer.jpg')
}

h1 {
  margin: 50px 0 30px 0;
  color: #666666;
  font-size: 30px;
}
p {
  color: #666666;
  font-size: 14px;
}
#OAOnline-img {
  height: 300px;
  cursor: default;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  overflow: hidden;
  display: block;
  outline: none;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  background-size: cover;
  background-image: url(//22159555.s21i.faiusr.com/4/ABUIABAEGAAg1_CT8wUoyNSA-AEwgA84rAI.png.webp);
}

</style>